import { ref } from 'vue'
import type { Router } from 'vue-router'
import router from '@/router'
import { useUserStore } from '@/stores/user'

export const useRegister = () => {
  const username = ref('')
  const password = ref('')
  const confirmPassword = ref('')
  const userStore = useUserStore()

  const handleRegister = async () => {
    if (password.value !== confirmPassword.value) {
      alert('两次输入的密码不一致')
      return
    }

    try {
      // 这里添加注册逻辑
      await userStore.setUserInfo({ username: username.value })
      router.push('/login')
    } catch (error) {
      console.error('注册失败:', error)
    }
  }

  return {
    username,
    password,
    confirmPassword,
    handleRegister
  }
} 